package com.ruoyi.door.service;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.door.controller.admin.dept.vo.DoorDeptPriceCreateReqVO;
import com.ruoyi.door.controller.admin.dept.vo.DoorDeptPriceRespVO;
import com.ruoyi.door.domain.DoorHouse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.door.domain.DoorDeptPrice;
import com.easy.query.api.proxy.client.EasyEntityQuery;

/**
 * 镇街价格Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-27
 */
@Service
@Slf4j
public class DoorDeptPriceService {
    @Autowired
    private EasyEntityQuery easyEntityQuery;

    /**
     * 查询镇街价格
     *
     * @param deptId 镇街价格主键
     * @return 镇街价格
     */
    public DoorDeptPriceRespVO selectDoorDeptPriceById(Long deptId) {
        DoorDeptPrice priceList = easyEntityQuery.queryable(DoorDeptPrice.class)
                .where(x -> {
                    x.deptId().eq(deptId);
                })
                .firstOrNull();
        if (priceList==null){
            priceList=new DoorDeptPrice();
            priceList.setDeptId(deptId);
        }
        return BeanUtil.copyProperties(priceList, DoorDeptPriceRespVO.class);
    }


    /**
     * 新增镇街价格
     *
     * @param doorDeptPrice 镇街价格
     * @return 结果
     */
    public long insertDoorDeptPrice(DoorDeptPriceCreateReqVO doorDeptPrice) {
        easyEntityQuery.deletable(DoorDeptPrice.class)
                .allowDeleteStatement(true)
                .disableLogicDelete()
                .where(x -> x.deptId().eq(doorDeptPrice.getDeptId()))
                .executeRows();
        DoorDeptPrice deptPrice = new DoorDeptPrice();
        deptPrice.setCreateTime(DateUtils.getNowDate());
        deptPrice.setUpdateTime(DateUtils.getNowDate());
        deptPrice.setDeptId(doorDeptPrice.getDeptId());
        deptPrice.setInstallPrice(doorDeptPrice.getInstallPrice());
        deptPrice.setCardPrice(doorDeptPrice.getCardPrice());
        deptPrice.setGiftMonthOfByOneYear(doorDeptPrice.getGiftMonthOfByOneYear());
        deptPrice.setInstruction(deptPrice.getInstruction());
        deptPrice.setNum(deptPrice.getNum());
        deptPrice.setRemark1(deptPrice.getRemark1());
        deptPrice.setRemark2(deptPrice.getRemark2());
        deptPrice.setRemark3(deptPrice.getRemark3());
        deptPrice.setRemark4(deptPrice.getRemark4());
        deptPrice.setRemark5(deptPrice.getRemark5());
        easyEntityQuery.insertable(deptPrice).executeRows();


        return 1;
    }

    public long delete(Long deptId) {
        easyEntityQuery.deletable(DoorDeptPrice.class)
                .allowDeleteStatement(true)
                .disableLogicDelete()
                .where(x -> x.deptId().eq(deptId))
                .executeRows();
        return 1;
    }
}